//
//  HomePresenter.swift
//  MyNoteDemo4
//
//  Created by BZF on 2020/8/25.
//  Copyright © 2020 bzf. All rights reserved.
//

import Foundation
import UIKit

public class HomePresenter{
    
    
    public func getAll(){
        
        NoteRespository.instance.getAll(handler: { response in
            print(response.value)
            do{

                if let nsDictionary  = response.value as? NSDictionary{
                     print("Dictionary",nsDictionary)
                    
                    if let items = nsDictionary.value(forKey: "Record") as? NSArray{
                       
                        let listData = 
                        
                        for item in items {
                            let dict = item as? NSDictionary
                            let strDate = dict?.value(forKey: "CDate") as! String
                            
                            let note = Note()
                            let dateFormatter = DateFormatter()
                            dateFormatter.dateFormat = "yyyy-MM-dd"
                        
                            note.date = dateFormatter.date(from: strDate) as! NSDate
                            note.content = dict?.value(forKey: "Content") as! String
                            self.listData.add(note)
                           print("note",note)
                        }
                        
                        
                        DispatchQueue.main.async {
                              self.tableView.reloadData()
                        }
                    }
                }
            }catch{
                print("解析json失败")
            }
        })
    }
    
}
